package org.hnxxxy.ebms.controller;


import io.swagger.annotations.ApiOperation;
import org.hnxxxy.ebms.common.Result;
import org.hnxxxy.ebms.pojo.Admission;
import org.hnxxxy.ebms.pojo.Expense;
import org.hnxxxy.ebms.service.AdmissionService;
import org.hnxxxy.ebms.service.ExpenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WANGWEI
 * @since 2021-06-10
 */
@RestController
@RequestMapping("//admission")
public class AdmissionController {

    @Autowired
    public AdmissionService admissionService;

    @PostMapping("/add")
    @ApiOperation(value = "增加地区")
    public Result<String> addAdmission(@RequestBody Admission admission){
        if (admissionService.save(admission)){
            return Result.success(200,"添加成功");
        }
        return Result.fail("添加失败");
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除地区")
    public Result<String> delAdmission(@PathVariable("id") Integer id){
        if (admissionService.delById(id)){
            return Result.success(200,"删除成功");
        }
        return Result.fail("删除失败");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改地区")
    public Result<String> updateAdmission(@RequestBody Admission admission){
        if (admissionService.updateById(admission)){
            return Result.success(200,"修改成功");
        }
        return Result.fail("删除失败");
    }

    @GetMapping("/get")
    @ApiOperation(value = "查询地区")
    public Result<List<Admission>> getAdmission(){
        return Result.success(admissionService.list());
    }


}
